package butines.game.steering;

import butines.core.math2d.Vector2D;

public class Transformation {

	private Vector2D position = new Vector2D();
	private Vector2D forward = new Vector2D();
	private Vector2D side = new Vector2D();
	
	private Vector2D localPoint   = new Vector2D();
	private Vector2D localVector  = new Vector2D();
	private Vector2D globalPoint  = new Vector2D();
	private Vector2D globalVector = new Vector2D();
	
	public Vector2D toLocalPoint(Vector2D globalPoint) {
		float newX = forward.x * globalPoint.x + forward.y * globalPoint.y + (-position.dot(forward));
		float newY = side.x    * globalPoint.x + side.y    * globalPoint.y + (-position.dot(side));
		localPoint.set(newX, newY);
		return localPoint;
	}

	public Vector2D toLocalVector(Vector2D globalVector) {
		float newX = forward.x * globalVector.x + forward.y * globalVector.y;
		float newY = side.x    * globalVector.x + side.y    * globalVector.y;
		localVector.set(newX, newY);
		return localVector;
	}
	
	public Vector2D toGlobalPoint(Vector2D localPoint) {
		float newX = forward.x * localPoint.x + side.x * localPoint.y + position.x;
		float newY = forward.y * localPoint.x + side.y * localPoint.y + position.y;
		globalPoint.set(newX, newY);
		return globalPoint;
	}
	
	public Vector2D toGlobalVector(Vector2D localVector) {
		float newX = forward.x * localVector.x + side.x * localVector.y;
		float newY = forward.y * localVector.x + side.y * localVector.y;
		globalVector.set(newX, newY);
		return globalVector;
	}

	public Vector2D getForward() {
		return forward;
	}

	public void setForward(Vector2D forward) {
		this.forward = forward;
	}

	public Vector2D getSide() {
		return side;
	}

	public void setSide(Vector2D side) {
		this.side.set(side);
	}

	public Vector2D getPosition() {
		return position;
	}

	public void setPosition(Vector2D position) {
		this.position = position;
	}

	public Vector2D getLocalPoint() {
		return localPoint;
	}

	public Vector2D getLocalVector() {
		return localVector;
	}

	public Vector2D getGlobalPoint() {
		return globalPoint;
	}

	public Vector2D getGlobalVector() {
		return globalVector;
	}
		
}
